﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace APIBetaSeries.Tools
{
    public class MD5Hasher
    {
        public static String Hash(String value)
        {
            String reponse;
            if (String.IsNullOrEmpty(value))
                reponse = String.Empty;
            else
            {
                MD5 md5 = MD5.Create();
                byte[] inputBytes = Encoding.ASCII.GetBytes(value);
                byte[] hash = md5.ComputeHash(inputBytes);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hash.Length; i++)
                {
                    sb.Append(hash[i].ToString("X2"));
                }
                reponse = sb.ToString();
            }

            return reponse;
        }
    }
}
